<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>027-闭包的作用-函数防抖debounce.html</title>
	<style>
		body{
			width: 3000px;
			height: 3000px;
		}
	</style>
</head>
<body>
	
</body>
<script>
	var i = 0;
	function debounce(fn,delay){
		var timer = 0;
		return function(){
			clearTimeout(timer);
			timer = setTimeout(fn,delay);
		}
	}
	/*
	window.onscroll = function(){
		console.log(i++);
	}
	*/
	window.onscroll = debounce(function(){
		console.log(i++);
	},500)
</script>
</html>